package com.example.java_websocket.web.controller;


import com.example.java_websocket.service.IOnlineUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/onlineUsers")
@Api(tags = "观察聊天接口")
public class OnlineUserController {

    @Autowired
    private IOnlineUserService onlineUserService;

    // 用户上线
    @PostMapping("/login")
    @ApiOperation("用户上线接口")
    public String userLogin(@RequestParam String userId) {
        onlineUserService.userLogin(userId);
        return "User " + userId + " logged in successfully.";
    }

    // 用户下线
    @PostMapping("/logout")
    @ApiOperation("用户下线接口")
    public String userLogout(@RequestParam String userId) {
        onlineUserService.userLogout(userId);
        return "User " + userId + " logged out successfully.";
    }

    // 获取在线用户列表
    @GetMapping("/list")
    @ApiOperation("获取在线用户列表接口")
    public Set<String> getOnlineUsers() {
        return onlineUserService.getOnlineUsers();
    }
}
